package com.glory.wxelectricitypda.bean;

import android.content.Context;
import android.widget.Toast;

import com.pda.platform.ui.ui_pdaplatform.utils_public.FreeApi_ToastUtils;

import java.io.Serializable;
import java.util.ArrayList;

/**
 * @author lx
 * @date 2019/1/10
 * @desc
 */

public class BaseResponseBean<T> implements Serializable {

    private ResponseBean<T> Response;

    public ResponseBean<T> getResponse() {
        return Response;
    }

    public void setResponse(ResponseBean<T> response) {
        Response = response;
    }


    //获取到对象后，必须要判断是否获取成功
    public boolean isSuccess(Context context, boolean isHaveBody) {
        if (Response.getHeader().getRESULT().toUpperCase().equals("SUCCESS")) {
            if (isHaveBody) {
                if (Response.getBody() == null) {
                    FreeApi_ToastUtils.showFreeToast("暂无请求内容", context, false, Toast.LENGTH_SHORT);
                    return false;
                } else {
                    if (Response.getBody() instanceof ArrayList) {
                        if (((ArrayList) Response.getBody()).size() > 0) {
                            return true;
                        } else {
                            FreeApi_ToastUtils.showFreeToast("暂无请求数据", context, false, Toast.LENGTH_SHORT);
                            return false;
                        }
                    } else {
                        return true;
                    }
                }
            } else {
                return true;
            }
        } else {
            FreeApi_ToastUtils.showFreeToast(Response.getHeader().getRESULTMESSAGE(), context, false, Toast.LENGTH_SHORT);
            return false;
        }
    }

    public boolean isEapSuccess(Context context, boolean isHaveBody) {
        if (Response.getReturn().getReturnCode().equals("200")) {
            if (isHaveBody) {
                if (Response.getBody() == null) {
                    FreeApi_ToastUtils.showFreeToast("暂无请求内容", context, false, Toast.LENGTH_SHORT);
                    return false;
                } else {
                    if (Response.getBody() instanceof ArrayList) {
                        if (((ArrayList) Response.getBody()).size() > 0) {
                            return true;
                        } else {
                            FreeApi_ToastUtils.showFreeToast("暂无请求数据", context, false, Toast.LENGTH_SHORT);
                            return false;
                        }
                    } else {
                        return true;
                    }
                }
            } else {
                return true;
            }
        } else {
            FreeApi_ToastUtils.showFreeToast(Response.getReturn().getReturnMessage(), context, false, Toast.LENGTH_SHORT);
            return false;
        }
    }
}
